"""add dictionary tables

Revision ID: 3b2f55ffb2f2
Revises: f6229d3451be
Create Date: 2025-10-24 12:00:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '3b2f55ffb2f2'
down_revision = 'f6229d3451be'
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        'sys_dict_type',
        sa.Column('dict_name', sa.String(length=100), nullable=False, server_default=''),
        sa.Column('dict_type', sa.String(length=100), nullable=False),
        sa.Column('status', sa.String(length=1), nullable=False, server_default='0'),
        sa.Column('remark', sa.String(length=500), nullable=True),
        sa.Column('create_by', sa.String(length=64), nullable=True),
        sa.Column('update_by', sa.String(length=64), nullable=True),
        sa.Column('id', sa.UUID(), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('dict_type')
    )
    op.create_index(
        op.f('ix_sys_dict_type_dict_type'),
        'sys_dict_type',
        ['dict_type'],
        unique=True
    )

    op.create_table(
        'sys_dict_data',
        sa.Column('dict_sort', sa.Integer(), nullable=False, server_default='0'),
        sa.Column('dict_label', sa.String(length=100), nullable=False, server_default=''),
        sa.Column('dict_value', sa.String(length=100), nullable=False, server_default=''),
        sa.Column('dict_type', sa.String(length=100), nullable=False),
        sa.Column('css_class', sa.String(length=100), nullable=True),
        sa.Column('list_class', sa.String(length=100), nullable=True),
        sa.Column('is_default', sa.String(length=1), nullable=False, server_default='N'),
        sa.Column('status', sa.String(length=1), nullable=False, server_default='0'),
        sa.Column('remark', sa.String(length=500), nullable=True),
        sa.Column('create_by', sa.String(length=64), nullable=True),
        sa.Column('update_by', sa.String(length=64), nullable=True),
        sa.Column('dict_type_id', sa.UUID(), nullable=False),
        sa.Column('id', sa.UUID(), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(['dict_type_id'], ['sys_dict_type.id'], ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(
        op.f('ix_sys_dict_data_dict_type'),
        'sys_dict_data',
        ['dict_type'],
        unique=False
    )


def downgrade() -> None:
    op.drop_index(op.f('ix_sys_dict_data_dict_type'), table_name='sys_dict_data')
    op.drop_table('sys_dict_data')
    op.drop_index(op.f('ix_sys_dict_type_dict_type'), table_name='sys_dict_type')
    op.drop_table('sys_dict_type')
